package inutan.login;

import inutan.login.controller.CommonController;
import inutan.login.controller.LoginController;
import org.ricks.boot.Ricks;
import org.ricks.common.ModularContext;
import org.ricks.common.conf.RicksPropertiesLoader;
import org.ricks.common.lang.ClassScanner;
import org.ricks.net.http.HttpBootstrap;
import org.ricks.net.http.RestfulHandler;

import java.util.Set;

/**
 * @author chenwei
 * @date 2023/1/416:23
 *
 * 玩家只要走http登陆 。就认为需要重新分配网关节点。客户端那边就会创建一个新得KCP会话 新得KCP SESSION.绑定新得UserSession
 * 如果重新走http登陆逻辑，是不是意味KCP心跳断了 客户端菊花重连不上
 *
 */
public class LoginMain {

    public static void main(String[] args) {

        ModularContext.me().scan(Set.of("inutan.login","inutan.common.config.datasource","inutan.common.entity"));
        //加载配置文件
        RicksPropertiesLoader.loadingProperties();

        Ricks.run(LoginBootstrap.class);//启动容器 & 启动server
//        ServerSSLContextFactory serverFactory = new ServerSSLContextFactory(LoginMain.class.getClassLoader().getResourceAsStream("server.keystore"), "123456", "123456");
//        SslPlugin<Integer> sslServerPlugin = new SslPlugin<>(serverFactory, ClientAuth.OPTIONAL);
//        NetContext.me().init();

        RestfulHandler restfulHandler = new RestfulHandler();
        restfulHandler.addController(LoginController.class);
        restfulHandler.addController(CommonController.class);
        HttpBootstrap bootstrap = new HttpBootstrap().setPort(8080);
        bootstrap.httpHandler(restfulHandler);
        bootstrap.configuration()
                .threadNum(Runtime.getRuntime().availableProcessors())
                .readBufferSize(1024 * 4)
                .writeBufferSize(1024 * 4)
                .readMemoryPool(16384 * 1024 * 4)
                .writeMemoryPool(10 * 1024 * 1024 * Runtime.getRuntime().availableProcessors(), Runtime.getRuntime().availableProcessors()).debug(false);
        bootstrap.start();
    }
}
